<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="b" uri="/WEB-INF/tld/blank.tld" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>景区信息编辑</title>
<%@include file="../header.jsp" %>
<!-- 配置文件 -->
<script type="text/javascript" src="/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="/ueditor/ueditor.all.js"></script>
<script type="text/javascript" src="/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="/js/area-select.js"></script>

<!-- jquery fileupload -->
<script type="text/javascript" src="/js/vendor/jquery.ui.widget.js"></script>  
<script type="text/javascript" src="/js/jquery.iframe-transport.js"></script>  
<script type="text/javascript" src="/js/jquery.fileupload.js"></script>
<link rel="stylesheet" href="/css/jquery.fileupload.css">
<script type="text/javascript">
	$(function() {
    	var ue1 = UE.getEditor('aboutUs_editor',{initialFrameWidth:900});
    	
    	$("#distributor-logo").fileupload({  
    	    url:"/common/upload.htm",//文件上传地址，当然也可以直接写在input的data-url属性内  
    	    formData:{type:"distributor"},//如果需要额外添加参数可以在这里添加  
    	    done:function(e,data){  
    	        //done方法就是上传完毕的回调函数，其他回调函数可以自行查看api  
    	        //注意result要和jquery的ajax的data参数区分，这个对象包含了整个请求信息  
    	        //返回的数据在result.result中，假设我们服务器返回了一个json对象  
    	        //console.log(JSON.stringify(result.result)); 
    	        var ret = eval("("+data.result+")");
    	        if(ret.isSuccess) {
    	        	var url = ret.json.url;
    	        	$("#distributor-logo").next().val("http://file.teziyou.com"+url);
    	        	$("#img1").attr("src", "http://file.teziyou.com"+url);
    	        } 
    	    }  
    	}) 
    	
    	$("#distributor-cert").fileupload({  
    	    url:"/common/upload.htm",//文件上传地址，当然也可以直接写在input的data-url属性内  
    	    formData:{type:"distributor"},//如果需要额外添加参数可以在这里添加  
    	    done:function(e,data){  
    	        //done方法就是上传完毕的回调函数，其他回调函数可以自行查看api  
    	        //注意result要和jquery的ajax的data参数区分，这个对象包含了整个请求信息  
    	        //返回的数据在result.result中，假设我们服务器返回了一个json对象  
    	        //console.log(JSON.stringify(result.result)); 
    	        var ret = eval("("+data.result+")");
    	        if(ret.isSuccess) {
    	        	var url = ret.json.url;
    	        	$("#distributor-cert").next().val("http://file.teziyou.com"+url);
    	        	$("#img2").attr("src", "http://file.teziyou.com"+url);
    	        } 
    	    }  
    	})
    	
    	$("#savebtn").click(function() {
    		var admDivId = $("select[name='distributor.adm_div_id']").val();
    		if(admDivId==''||admDivId==null) {
    			alert("请填写分销商位置信息！！");
    			return;
    		}
    		$.ajax({
    			url:"/distributor/update",
    			type:"post",
    			data:$("#distributor-form").serialize(),
    			dataType:"json"
    		}).done(function(data) {
    			alert(data.msg);
    			if(data.isSuccess) 
    				window.location = "/distributor/list";
    		})
    	})
    	
    	$("#province-select").val("${provinceId}");
    	$("#city-select").val("${cityId}");
    	$("#county-select").val("${countyId}");
    	
    	$("input[name='distributor.whoami'][value='${distributor.whoami}']").attr("checked",true)
	})
</script>
</head>
<body>
	<div class="ch-container">
		<div class="row">
		    <div class="box col-md-12">
		        <div class="box-inner">
		            <div class="box-header well" data-original-title="">
		                <h2><i class="glyphicon glyphicon-edit"></i> 分销商编辑</h2>
		                <div class="box-icon">
		                    <a href="javascript:;" class="btn btn-setting btn-round btn-default"><i
		                            class="glyphicon glyphicon-cog"></i></a>
		                    <a href="javascript:;" class="btn btn-minimize btn-round btn-default"><i
		                            class="glyphicon glyphicon-chevron-up"></i></a>
		                    <a href="javascript:;" class="btn btn-close btn-round btn-default"><i
		                            class="glyphicon glyphicon-remove"></i></a>
		                </div>
		            </div>
		            <div class="box-content">
		                <form class="form-inline" role="form" id="distributor-form">
		                	<input name="distributor.distributor_id" type="hidden" value="${distributor.distributor_id }">
		                    <div class="form-group">
		                        <label>分销商名称：<b:blank num="1"/></label>
		                        <input name="distributor.name" type="text" class="form-control" value="${distributor.name }">
		                    </div>
		                    <div class="clearfix"></div><br>
		                    <div class="form-group col-md-5">
		                        <label>公司logo：<b:blank num="2"/></label>
		                        <input id="distributor-logo" name="file" type="file" class="form-control">
		                        <input type="hidden" name="distributor.logo_pic" value="${distributor.logo_pic }">
		                        
		                    </div>
		                    <div class="form-group col-md-5">
		                        <label>营业执照：<b:blank num="2"/></label>
		                        <input id="distributor-cert" name="file" type="file" class="form-control">
		                        <input type="hidden" name="distributor.trading_certificate_URL"
		                        	value="${distributor.trading_certificate_URL }">
		                        <img src="" style="width:160;height:120;">
		                    </div>
		                    <div class="clearfix"></div><br>
		                    <div class="form-group col-md-5">
		                    	<img id="img1" src="${distributor.logo_pic }" width=160 height=120>
		                    </div>
		                    <div class="form-group col-md-5">
		                    	<img id="img2" src="${distributor.trading_certificate_URL }" width=160 height=120>
		                    </div>
		                    <div class="clearfix"></div><br>
		                    <div class="form-group">
		                        <label>关于分销商：</label>
		                        <!-- 加载编辑器的容器 -->
								<script id="aboutUs_editor" name="distributor.about_us" type="text/plain">${distributor.about_us }</script>
		                    </div>
		                    <div class="clearfix"></div><br>
		                    <div class="form-group">
		                        <label>分销商位置：<b:blank num="1"/></label>
		                        <span>
		                        <select id="province-select" class="area-select form-control">
		                        	<option value="">--请选择--</option>
		                        	<c:forEach items="${provinces }" var="province">
		                        		<option value="${province.adm_div_id }">${province.Name }</option>
		                        	</c:forEach>
		                        </select>
		                        <select id="city-select" class="area-select form-control">
		                        	<option value="">--请选择--</option>
		                        	<c:forEach items="${citys }" var="city">
		                        		<option value="${city.adm_div_id }">${city.Name }</option>
		                        	</c:forEach>
		                        </select>
		                        <select id="county-select" name="distributor.adm_div_id" class="area-select form-control">
		                        	<option value="">--请选择--</option>
		                        	<c:forEach items="${countys }" var="county">
		                        		<option value="${county.adm_div_id }">${county.Name }</option>
		                        	</c:forEach>
		                        </select>
		                        </span>
		                        <input id="fullAddress" name="distributor.office_address" type="text" class="form-control"
		                        	 value="${distributor.office_address }">
		                    </div>
		                    <div class="clearfix"></div><br>
		                    <div class="form-group col-md-5">
		                        <label>联系电话：<b:blank num="1"/></label>
		                        <input name="distributor.phone_NO" type="text" class="form-control"
		                        	value="${distributor.phone_NO }">
		                    </div>
		                    <div class="form-group col-md-5">
		                        <label>传真：<b:blank num="3"/></label>
		                        <input type="text" class="form-control">
		                    </div>
		                    <div class="clearfix"></div><br>
		                    <div class="form-group col-md-5">
		                        <label>400电话：<b:blank num="1"/></label>
		                        <input name="distributor.phone_400" type="text" class="form-control"
		                        	value="${distributor.phone_400 }">
		                    </div>
		                    <div class="form-group col-md-5">
		                        <label>邮政编码：<b:blank num="1"/></label>
		                        <input name="distributor.post_code" type="text" class="form-control"
		                        	value="${distributor.post_code }">
		                    </div>
		                    <div class="clearfix"></div><br>
		                    <div class="form-group col-md-5">
		                        <label>注册资本：<b:blank num="1"/></label>
		                        <input name="distributor.registered_capital" type="text" class="form-control"
		                        	value="${distributor.registered_capital }">万元
		                    </div>
		                    <div class="form-group col-md-5">
		                        <label>法人代表：<b:blank num="1"/></label>
		                        <input name="distributor.juridical_person" type="text" class="form-control"
		                        	value="${distributor.juridical_person }">
		                    </div>
		                    <div class="clearfix"></div><br>
		                    <div class="form-group">
		                        <label>组织机构代码：</label>
		                        <input name="distributor.organize_code" type="text" class="form-control"
		                        	value="${distributor.organize_code }">
		                    </div>
		                    <div class="clearfix"></div><br>
		                    <div class="form-group">
		                        <label>创建日期：<b:blank num="2"/></label>
		                        <input name="distributor.found_date" type="text" class="form-control" onClick="WdatePicker()"
		                        	readonly="readonly" value="${distributor.found_date }">
		                    </div>
		                    <div class="clearfix"></div><br>
		                    <div class="form-group">
		                        <label>官网：<b:blank num="4"/></label>
		                        <input name="distributor.http_www" type="text" class="form-control"
		                        	value="${distributor.http_www }">
		                    </div>
		                    <div class="clearfix"></div><br>
		                    <div class="form-group">
		                        <label>微博：<b:blank num="4"/></label>
		                        <input name="distributor.weibo" type="text" class="form-control"
		                        	value="${distributor.weibo }">
		                    </div>
		                    <div class="clearfix"></div><br>
		                    <div class="form-group">
		                        <label>微信服务号：<b:blank num="1"/></label>
		                        <input name="distributor.weixin_service" type="text" class="form-control"
		                        	value="${distributor.weixin_service }">
		                    </div>
		                    <div class="clearfix"></div><br>
		                    <div class="form-group">
		                        <label>微信订阅号：<b:blank num="1"/></label>
		                        <input name="distributor.weixin_subscription" type="text" class="form-control"
		                        	value="${distributor.weixin_subscription }">
		                    </div>
		                    <div class="clearfix"></div><br>
		                    <div class="form-group">
		                    	<label>我自己：<b:blank num="3"/></label>
		                    	<label class="radio-inline">
				                    <input type="radio" name="distributor.whoami" value="1" checked="checked">是
				                </label>
				                <label class="radio-inline">
				                    <input type="radio" name="distributor.whoami" value="0">不是
				                </label>
		                    </div>
		                    <div class="clearfix"></div><br>
		                    <button type="button" class="btn btn-default" id="savebtn">保存</button>
		                </form>
		            </div>
		        </div>
		    </div>
		    <!--/span-->
		</div><!--/row-->
	</div>
</body>
</html>